import 'package:common/smart_dialog/smart_dialog.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';

class IntegralWxchangeWidget extends StatefulWidget {
  const IntegralWxchangeWidget({super.key});

  @override
  State<IntegralWxchangeWidget> createState() => _IntegralWxchangeWidgetState();
}

class _IntegralWxchangeWidgetState extends State<IntegralWxchangeWidget> {
  TextEditingController controller = TextEditingController();
  FocusNode focusNode = FocusNode();

  @override
  void initState() {
    controller = TextEditingController(text: '');
    super.initState();
  }

  @override
  Widget build(BuildContext context) {
    return Container(
      width: 295,
      height: 217,
      decoration: BoxDecoration(color: Colors.white, borderRadius: BorderRadius.circular(16)),
      padding: EdgeInsets.symmetric(horizontal: 20.w),
      child: Column(
        crossAxisAlignment: CrossAxisAlignment.start,
        children: [
          Container(
              margin: EdgeInsets.only(top: 20.h),
              child: Center(
                  child: Text('兑换金币',
                      style: TextStyle(color: Colors.black, fontSize: 18.sp, fontWeight: FontWeight.w600)))),
          Expanded(
              child: Center(
            child: Container(
              height: 50,
              decoration: BoxDecoration(
                  borderRadius: BorderRadius.circular(25),
                  border: Border.all(color: const Color(0xFFEEEEEE), width: 1)),
              child: Row(
                children: [
                  Expanded(
                    child: Container(
                      padding: EdgeInsets.only(left: 10.h),
                      alignment: Alignment.centerLeft,
                      child: SizedBox(
                        child: TextField(
                          maxLength: 10,
                          focusNode: focusNode,
                          controller: controller,
                          obscureText: false,
                          // cursorWidth: 2,
                          maxLines: 1,
                          cursorColor: const Color(0xFF2CC0B1),
                          // cursorHeight: 18.h,
                          autofocus: false, // 指不自动获取焦点
                          onChanged: (value) {
                            setState(() {});
                          },
                          onSubmitted: (value) {
                            // widget.onSubmit?.call();
                          },
                          keyboardType: TextInputType.phone,
                          inputFormatters: [
                            FilteringTextInputFormatter.allow(RegExp(r'[0-9]')) //设置只允许输入数字
                          ],
                          style: TextStyle(color: const Color(0xFF000000), fontSize: 12.sp),
                          decoration: InputDecoration(
                            hintText: '请输入要兑换的积分数量',
                            counterText: '',
                            hintStyle: TextStyle(color: const Color(0xFF999999), fontSize: 12.sp),
                            border: InputBorder.none,
                          ),
                        ),
                      ),
                    ),
                  ),
                  Container(color: const Color(0xFFEEEEEE), width: 1, height: 20),
                  SizedBox(
                      width: 80,
                      child: Center(
                          child: Text("全部兑换", style: TextStyle(color: const Color(0xFF25D4D0), fontSize: 12.sp)))),
                ],
              ),
            ),
          )),
          SizedBox(
              height: 30, child: Text('最多可兑换1000金币，兑换比例 1:1', style: TextStyle(color: Colors.black, fontSize: 12.sp))),
          SizedBox(
            height: 40,
            child: Row(
              mainAxisAlignment: MainAxisAlignment.spaceBetween,
              children: [Expanded(child: leftButton()), const SizedBox(width: 20), Expanded(child: rightButton())],
            ),
          ),
          const SizedBox(height: 20),
        ],
      ),
    );
  }

  Widget leftButton() {
    return GestureDetector(
      onTap: () {
        SmartDialog.dismiss();
      },
      child: Container(
        height: 40.h,
        alignment: Alignment.center,
        decoration: BoxDecoration(
            borderRadius: BorderRadius.all(Radius.circular(22.r)),
            border: Border.all(color: const Color(0xFF25D4D0), width: 1)),
        child: Text("取消", style: TextStyle(color: const Color(0xFF25D4D0), fontSize: 16.sp)),
      ),
    );
  }

  Widget rightButton() {
    return GestureDetector(
      onTap: () {
        SmartDialog.dismiss();
      },
      child: Container(
        height: 40.h,
        alignment: Alignment.center,
        decoration: BoxDecoration(
            color: const Color(0xFF25D4D0),
            borderRadius: BorderRadius.all(Radius.circular(22.r)),
            border: Border.all(color: const Color(0xFF25D4D0), width: 1)),
        child: Text("确定", style: TextStyle(color: const Color(0xFFFFFFFF), fontSize: 16.sp)),
      ),
    );
  }
}
